fix: default to bounded LRU cache instead of unbounded simple cache#1444
Open
jgowdy-godaddy wants to merge 4 commits intomainfrom
Open
fix: default to bounded LRU cache instead of unbounded simple cache#1444jgowdy-godaddy wants to merge 4 commits intomainfrom
jgowdy-godaddy wants to merge 4 commits intomainfrom
Conversation
The simple cache implementation never evicts keys, leading to unbounded memory growth. In production systems with many partitions/users, this causes OOM issues. Changes: - Add DefaultKeyCacheEvictionPolicy constant set to "lru" - Update NewCryptoPolicy to set eviction policies to LRU by default - Update documentation to reflect new defaults - Add tests to verify default behavior This ensures that by default, caches have a maximum size (1000 entries) and use LRU eviction when full. Users can still explicitly set "simple" if they need the old unbounded behavior. Breaking change: The default cache behavior now evicts old entries when the cache is full. This is safer for production use but may impact systems that relied on unbounded caching.
- Fix gofmt formatting in policy.go - Fix gci import ordering in policy_test.go
- Set default eviction policy to 'lru' in NewCryptoPolicy() - This prevents unbounded memory growth in production systems - Maintain backward compatibility - users can still set 'simple' if needed - Update benchmark tests to use simple cache since they access internals - Add test to verify new defaults are set correctly
28f9e9f to
8ee3d20
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
The Problem
The current default cache implementation uses
simpleCachewhich:The code even has a comment warning about this:
The Solution
This PR changes the default eviction policy from empty string (which becomes "simple") to "lru":
Added constants:
Updated NewCryptoPolicy to set these defaults
Updated documentation to reflect the new defaults
Why LRU is the Better Default
1. Production Safety
2. Real-World Usage Patterns
3. Performance Characteristics
4. Fail-Safe Defaults
5. Industry Best Practices
Impact
Breaking Change
This is technically a breaking change as the default behavior changes from unbounded to bounded caching. However:
evictionPolicy = "simple"if they need unbounded cachingTesting
Added tests to verify:
Migration Guide
If you require the old unbounded behavior, explicitly set the eviction policy:
However, we strongly recommend evaluating whether bounded caching would work for your use case, as it provides better production stability.